﻿
using System.Windows.Forms;
namespace SpeedSearch
{
    /// <summary>
    /// Unité de traitement de virtualisation.
    /// Contient les éléments graphiques, la configuration
    /// </summary>
    public class VirtualizationWorkUnit
    {
        public Virtual AssociatedConfig { get; set; }
        public VirtualizationTextBox AssociatedTextBox { get; set; }
        public VirtualizationPictureBox AssociatedStatePictureBox { get; set; }
        public VirtualizationPictureBox AssociatedWorkPictureBox { get; set; }

        public VirtualizationWorkUnit()
        {
            this.AssociatedConfig = new Virtual();
            this.AssociatedStatePictureBox = new VirtualizationPictureBox();
            this.AssociatedTextBox = new VirtualizationTextBox();
            this.AssociatedWorkPictureBox = new VirtualizationPictureBox();
        }

        public void AssociatedControlsToParent(Control parentControl)
        {
            parentControl.Controls.AddRange(new Control[] { this.AssociatedTextBox, this.AssociatedStatePictureBox, this.AssociatedWorkPictureBox });
        }

        /// <summary>
        /// Met à jour les composants associés en fonction de l'état de la config
        /// </summary>
        public void UpdateWorkUnitFromState()
        {
            this.AssociatedTextBox.Text = this.AssociatedConfig.RootPath;

            if (this.AssociatedConfig.IsVirtualized)
            {
                this.AssociatedStatePictureBox.SetImageAndToolTip("accept.png", "Ce dossier est virtualisé.");
                this.AssociatedWorkPictureBox.SetImageAndToolTip("stop.png", "Supprimer la virtualisation de ce dossier");
            }
            else
            {
                this.AssociatedStatePictureBox.SetImageAndToolTip("croix-rouge.png", "Ce dossier n'est pas virtualisé");
                this.AssociatedWorkPictureBox.SetImageAndToolTip("start-icon.gif", "Démarrer la virtualisation de ce répertoire");
            }
        }
    }
}
